load("scripts/test/test.js");
load("scripts/lib/panda/proxy.js");
load("scripts/test/lib/proxy/say.js");

test({
	name: function() {
		return "Proxy Test";
	},
	setUp: function() {
		proxy = { log: { priority: 100 } };		
		context = { msg: "", results: [] };
	},
	testNoMethod: function() {
		var say = panda.proxy("say");
		context.results.push(say.hello("John"));
		context.results.push(say.goodbye("John"));

		Assert.assertEquals("", context.msg);
		Assert.assertEquals("Hello, John!", context.results[0]);
		Assert.assertEquals("Goodbye, John!", context.results[1]);
	},
	testSingleMethod: function() {
		load("scripts/test/lib/proxy/sayLog.js");

		var say = panda.proxy("say");
		context.results.push(say.hello("John"));
		context.results.push(say.goodbye("John"));

		var expectedMsg = "Before Say..."
				+ "After Say..."
				+ "Before Say..."
				+ "After Say...";

		Assert.assertEquals(expectedMsg, context.msg);
		Assert.assertEquals("Hello, John!", context.results[0]);
		Assert.assertEquals("Goodbye, John!", context.results[1]);
	},
	testMultiMethods: function() {
		load("scripts/test/lib/proxy/sayLog.js");
		load("scripts/test/lib/proxy/helloLog.js");

		var say = panda.proxy("say");
		context.results.push(say.hello("John"));
		context.results.push(say.goodbye("John"));

		var expectedMsg = "Before Say..."
				+ "Before Say Hello..."
				+ "After Say Hello..."
				+ "After Say..."
				+ "Before Say..."
				+ "After Say...";

		Assert.assertEquals(expectedMsg, context.msg);
		Assert.assertEquals("Hello, John!", context.results[0]);
		Assert.assertEquals("Goodbye, John!", context.results[1]);
	},
	testMultiProxies: function() {
		load("scripts/test/lib/proxy/sayLog.js");
		load("scripts/test/lib/proxy/helloLog.js");
		load("scripts/test/lib/proxy/another.js");

		var say = panda.proxy("say");
		context.results.push(say.hello("John"));
		context.results.push(say.goodbye("John"));

		var expectedMsg = "Before Say..."
				+ "Before Say Hello..."
				+ "method: hello"
				+ "args[0]: John"
				+ "return: Hello, John!"
				+ "After Say Hello..."
				+ "After Say..."
				+ "Before Say..."
				+ "After Say...";

		Assert.assertEquals(expectedMsg, context.msg);
		Assert.assertEquals("Hello, John!", context.results[0]);
		Assert.assertEquals("Goodbye, John!", context.results[1]);
	},
	testCallOtherMethod: function() {
		load("scripts/test/lib/proxy/sayLog.js");
		load("scripts/test/lib/proxy/helloLog.js");

		var say = panda.proxy("say");
		context.results.push(say.helloAndGoodbye("John"));

		var expectedMsg = "Before Say..."
				+ "Before Say..."
				+ "Before Say Hello..."
				+ "After Say Hello..."
				+ "After Say..."
				+ "Before Say..."
				+ "After Say..."
				+ "After Say...";

		Assert.assertEquals(expectedMsg, context.msg);
		Assert.assertEquals("Hello, John!Goodbye, John!", context.results[0]);
	}
});
